package com.njcc.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.njcc.dao.PrintRecordDao;
import com.njcc.po.FileInfo;
import com.njcc.util.DBCon;

/**
 * 实现PrintRecordDao记录数据信息接口
 *
 */
public class PrintRecordDaoImpl implements PrintRecordDao{
	 Connection con = DBCon.getCon();
	 PreparedStatement ps = null;
	
	/**
	 * 向printrecord表中添加打印的记录数据
	 * @param fileInfo
	 * @return int
	 */
	@Override
	public int isnertRecord(FileInfo fileInfo){
		int i = 0;
		try {
			String sql = "insert into tbl_fileInfo (name,type,size,cost,printTime) values (?,?,?,?,?)";
			ps = con.prepareStatement(sql);
			ps.setString(1, fileInfo.getName());
			ps.setString(2, fileInfo.getKind());
			ps.setInt(3, fileInfo.getPages());
			ps.setDouble(4, fileInfo.getCost());
			ps.setString(5, new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
			i = ps.executeUpdate();
			
		} catch (Exception e) {
			System.out.println(e);
		} finally {
			DBCon.closeAll(null, ps, con);
		}
		return i;
	}
}
